package com.yanqu.road.server.cmd.chefduel.process3;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.S_CHEF_DUEL3_BANQUET_REWARDR_REQ, desc = "给玩家展示结束的奖励")
public class ChefDuel3GetBanquetRewardCmd extends AbstractCommand {

	int activityId;
	int banquetId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		ChefDuelProto.ChefDuel3BanquetRewardReqMsg reqMsg = ChefDuelProto.ChefDuel3BanquetRewardReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		banquetId = reqMsg.getBanquetId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo activityInfo = ChefDuelActivityMgr.getOpenActivityInfo(activityId);
		if(activityInfo == null){
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
			return;
		}
		ChefDuelProto.ChefDuel3BanquetRewardReqMsg.Builder reqMsg = ChefDuelProto.ChefDuel3BanquetRewardReqMsg.newBuilder();
		reqMsg.setActivityId(activityId);
		reqMsg.setBanquetId(banquetId);
		YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_CHEF_DUEL3_BANQUET_REWARD, reqMsg);
		GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			ChefDuelProto.ChefDuel3BanquetRewardRespMsg.Builder respMsg = ChefDuelProto.ChefDuel3BanquetRewardRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_CHEF_DUEL3_BANQUET_REWARDR_REQ, respMsg);
		}
	}
}
